<template>
  <div v-loading="loading">
    <!--订单进度-->
    <!--内容-->
    <!--基本信息-->
    <div class="common-form">基本信息</div>
    <el-form size="small" ref="form" :model="form" label-width="100px">
      <el-form-item label="发票抬头">
        {{ detail.invoice.title }}
      </el-form-item>
      <el-form-item label="纳税人识别号">
        {{ detail.invoice.code }}
      </el-form-item>
      <el-form-item label="地址">
        {{ detail.invoice.address }}
      </el-form-item>
      <el-form-item label="开户行">
        {{ detail.invoice.bank }}
      </el-form-item>
      <el-form-item label="银行帐号">
        {{ detail.invoice.bank_code }}
      </el-form-item>
      <el-form-item label="联系人">
        {{ detail.invoice.name }}
      </el-form-item>
      <el-form-item label="联系电话">
        {{ detail.invoice.phone }}
      </el-form-item>
      <el-form-item label="邮箱">
        {{ detail.invoice.email }}
      </el-form-item>
      <el-form-item label="提交时间">
        {{ detail.invoice.create_time }}
      </el-form-item>
      <el-form-item label="开票金额">
        {{ detail.order.pay_price }}
      </el-form-item>
    </el-form>

    <div class="common-button-wrapper">
      <el-button v-if="detail.order.is_invoice == 1" size="small" type="primary" @click="onSubmit()">确认开票</el-button>
      <el-button size="small" type="info" @click="cancelFunc">返回上一页</el-button>
    </div>
  </div>
</template>

<script>
import invoiceOrderApi from '@/api/invoiceOrder.js';
import {
  deepClone
} from '@/utils/base.js';

export default {
  components: {},
  data() {
    return {
      active: 0,
      /*是否加载完成*/
      loading: true,
      /*订单数据*/
      detail: {},
      /*发货*/
      form: {
        /*订单ID*/
        express_id: null,
        /*订单号*/
        express_no: ''
      },
    };
  },
  created() {
    /*获取列表*/
    this.getParams();
  },
  methods: {
    next() {
      if (this.active++ > 4) this.active = 0;
    },
    /*获取参数*/
    getParams() {
      let self = this;
      // 取到路由带过来的参数
      const params = this.$route.query.id;
      invoiceOrderApi.edit({
          id: params
        },
        true
      )
        .then(data => {
          self.loading = false;
          self.detail = data.data;
        })
        .catch(error => {
          self.loading = false;
        });
    },

    /*发货*/
    onSubmit() {
      let self = this;
      let id = this.detail.id;
      this.$confirm('确定开票吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        invoiceOrderApi.update({
            id: id
          },
          true
        )
          .then(data => {
            self.loading = false;
            self.$message({
              message: '恭喜你，操作成功',
              type: 'success'
            });
            this.$router.back(-1);
          })
          .catch(error => {
            self.loading = false;
          });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消开票'
        });
      });
    },

    /*确认取消*/
    confirmCancel() {
      let self = this;
      let order_id = this.$route.query.order_id;
      let is_cancel = self.forms.is_cancel;
      OrderApi.confirm({
          order_id: order_id,
          is_cancel: is_cancel
        },
        true
      )
        .then(data => {
          self.loading = false;
          self.$message({
            message: '恭喜你，审核成功',
            type: 'success'
          });
          self.getParams();
        })
        .catch(error => {
          self.loading = false;
        });
    },

    /*核销*/
    onExtract(e) {
      let self = this;
      let extract_form = self.extract_form;
      extract_form.order_id = e;
      OrderApi.extract({
          extract_form
        },
        true
      )
        .then(data => {
          self.loading = false;
          self.$message({
            message: '恭喜你，操作成功',
            type: 'success'
          });
          self.getParams();
        })
        .catch(error => {
          self.loading = false;
        });
    },
    /*虚拟商品发货*/
    onVirtual(e) {
      let self = this;
      let virtual_form = self.virtual_form;
      if (virtual_form.virtual_content == '') {
        this.$message.error('请填写发货信息');
        return;
      }
      virtual_form.order_id = e;
      OrderApi.virtual({
          order_id: virtual_form.order_id,
          virtual_content: virtual_form.virtual_content,
        },
        true
      )
        .then(data => {
          self.loading = false;
          self.$message({
            message: '恭喜你，操作成功',
            type: 'success'
          });
          self.getParams();
        })
        .catch(error => {
          self.loading = false;
        });
    },
    /*打开编辑*/
    editClick(item) {
      this.userModel = deepClone(item);
      this.open_edit = true;
    },

    /*关闭弹窗*/
    closeDialogFunc(e, f) {
      if (f == 'edit') {
        this.open_edit = e.openDialog;
        this.getParams();
      }
    },

    /*取消*/
    cancelFunc() {
      this.$router.back(-1);
    },
    changeAdd() {
      this.isChange = true;
    },
    closeAddress(e) {
      let self = this;
      if (e == false) {
        self.isChange = false;
        console.log(e)
        return false
      }
      let params = e.params;
      console.log(params)
      params.order_id = self.$route.query.order_id
      OrderApi.updateAddress(params,
        true
      )
        .then(data => {
          self.$message({
            message: '修改成功',
            type: 'success'
          });
        })
        .catch(error => {

        });
      self.isChange = false;
    }

  }
};
</script>
<style></style>
